package com.itheima.mapper;

import com.itheima.domain.NewTrip;
import com.itheima.domain.Trip;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface NewTripMapper {
    //使用蠕虫复制   编写SQL语句将旧数据导入到新表中
    @Insert("insert into tb_trip_new(user_id, from_address, to_address, start_time)\n" +
            "select u.id, t.from_address, t.to_address, t.start_time\n" +
            "from tb_trip t\n" +
            "         join tb_user u on u.username = t.username")
    void insert();

    //查询所有数据
    @Results({@Result(column="from_address",property="fromAddress")
            ,@Result(column="to_address",property="toAddress")
            ,@Result(column="start_time",property="startTime")})
    @Select("select ttn.id,tu.username,tu.gender,tu.idcard,ttn.from_address,ttn.to_address,ttn.start_time from tb_trip_new ttn join tb_user tu on ttn.user_id = tu.id")
    List<Trip> queryAll();

}
